# Adapted from https://glin.github.io/reactable/articles/cran-packages/cran-packages.html
row_details <- function(db, index) {
  f = function(index) {
    row = db[index]

    db_field = function(name, ...) {
      if (any(is.na(...))) NULL
      else tagList(div(class = "detail-label", name), ...)
    }

    detail = div(
      class = "db-detail",
      div(class = "detail-header", paste0("Dataset ID: ", row$dataset.id), span(class = "detail-title", paste0("Cohort ID: ", row$id))),
      div(class = "detail-description", paste0(row$dataset.name, " —— ", row$name)),
      db_field("Cancer type", row$cancer_type),
      db_field("Platform", row$dataset.data_platform),
      db_field("Data type", row$dataset.data_type),
      db_field("Data format", row$dataset.data_format),
      db_field("Tags", row$dataset.tags),
      db_field("Sample/Patient count", row$dataset.n),
      db_field("Genome build", row$dataset.genome_build),
      db_field("Data provider", row$data_provider),
      db_field("Maintainer", row$maintainer),
      db_field("DOI", row$doi)
    )

    detail
  }
  return(f)
}
